package com.rest.api.service.demo;

import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.stereotype.Component;

import com.rest.api.model.demo.Student;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Component("studentService")
@Path("/student/service")
@Api(value = "/student/service", tags = "Sample JAX-RS service with Swagger documentation")
@Produces(MediaType.APPLICATION_JSON)
public class StudenntServiceImpl implements StudentService {

	// 通过id查看学生信息
	@GET
	@Path("/{index}")
	@ApiOperation(value = "Get operation with type and headers", notes = "Get operation with type and headers", response = Student.class)
	@Override
	public Student getStudentById(
			@ApiParam(value = "index", required = true) @HeaderParam("Accept-Language") final Integer id) {

		Student student = null;
		if (id == 1) {
			student = new Student("张三", "男", 20);
		} else {
			student = new Student("李四娘", "女", 30);
		}
		return student;
	}

	// 查看所有学生信息
	@GET
	@Path("/list")
	@Override
	public List<Student> getStudentList() {
		List<Student> list = new ArrayList<Student>();
		Student student = new Student("张三", "男", 20);
		Student student1 = new Student("李四娘", "女", 30);
		Student student2 = new Student("李1娘", "女", 31);
		Student student3 = new Student("李2娘", "女", 32);
		Student student4 = new Student("李3娘", "女", 20);
		list.add(student);
		list.add(student1);
		list.add(student2);
		list.add(student3);
		list.add(student4);
		return list;
	}

	// 参看是否有这个学生
	@GET
	@Path("/status/{name}/{age}")
	@Override
	public String getStatus(@PathParam("name") String name, @PathParam("age") Integer age) {
		String flag = "FAULSE";
		if ("tom狗".equals(name) && age == 20) {
			flag = "TRUE";
		}
		return flag;
	}

}
